'use strict';

const conn = require('../../../libs/Conn');
const util = require('../../../libs/Utils');

module.exports = async function (params) {
    let checkDepartmentSql = `SELECT df.department_name FROM department_file df  WHERE df.department_name = ? AND delete_sign = 1`;
    let repeatData = (await conn(checkDepartmentSql, [params.department_name]));
    if (repeatData.shift()) {
        let repeat = `部门名称重复`;
        return {success: false, message: repeat};
    }/*else if(repeatData[1].shift()){
        let repeat = `部门编号重复`;
        return {success: false, message: repeat};
    }*/ else {
        let insertObj = {
            department_id:util.uuid(),
            department_name: params.department_name,
            departmental_functions: params.departmental_functions,
        };
        let insertSql = `insert into department_file set ?`;
        await conn(insertSql, [insertObj]);
        return {success: true};
    }
};